home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / rayshade / libshade / setup.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  6KB  |  267 lines

  1. /*
  2.  * setup.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: setup.c,v 1.1 1994/05/13 00:46:46 millard Exp millard $
  17.  *
  18.  * $Log: setup.c,v $
  19.  * Revision 1.1  1994/05/13  00:46:46  millard
  20.  * Initial revision
  21.  *
  22.  * Revision 4.0.1.2  92/01/14  18:29:35  cek
  23.  * patch3: Added initialization of cpp option.
  24.  * 
  25.  * Revision 4.0.1.1  91/09/29  15:52:20  cek
  26.  * patch1: Added crop window initialization.
  27.  * patch1: Moved RSViewing call to appropriate location.
  28.  * 
  29.  * Revision 4.0  91/07/17  14:47:24  kolb
  30.  * Initial version.
  31.  * 
  32.  */
  33. #include "rayshade.h"
  34. #include "defaults.h"
  35. #include "libsurf/surface.h"
  36. #include "libsurf/atmosphere.h"
  37. #include "liblight/light.h"
  38. #include "liblight/infinite.h"
  39. #include "libobj/list.h"
  40. #include "options.h"
  41. #include "stats.h"
  42. #include "viewing.h"
  43. #include "picture.h"
  44.  
  45. #ifdef MULTIMAX
  46. #include <parallel.h>
  47. #define SHARED_BYTES    23    /* 2^23 bytes of shared memory */
  48. #endif
  49.  
  50. #undef index
  51.  
  52. extern GeomList *Defstack;
  53.  
  54. static void SetupWorld();
  55.  
  56. /*
  57.  * Set default parameters
  58.  */
  59. void
  60. RSSetup()
  61. {
  62.     extern SurfList *CurSurf;
  63.     extern Medium TopMedium;
  64.     extern void NoiseInit();
  65. #ifdef MULTIMAX
  66.     unsigned int bytes;
  67.  
  68.     /*
  69.      * Initialize shared memory stuff.
  70.      */
  71.     bytes = 1 << SHARED_BYTES;
  72.     if (share_malloc_init(bytes) == -1) {
  73.         RLerror(RL_PANIC, "Cannot share_malloc %d bytes.\n",bytes);
  74.     } else
  75.         fprintf(fstats,"Malloced %d bytes of shared memory.\n",
  76.                 bytes);
  77. #endif
  78.  
  79.     Camera.hfov = HFOV;
  80.     Camera.vfov = UNSET;
  81.     Camera.pos.x = EYEX;
  82.     Camera.pos.y = EYEY;
  83.     Camera.pos.z = EYEZ;
  84.     Camera.lookp.x = LOOKX;
  85.     Camera.lookp.y = LOOKY;
  86.     Camera.lookp.z = LOOKZ;
  87.     Camera.up.x = UPX;
  88.     Camera.up.y = UPY;
  89.     Camera.up.z = UPZ;
  90.     Camera.focaldist = UNSET;
  91.     Camera.aperture = 0.;
  92.  
  93.     Screen.xres = Screen.yres = UNSET;
  94.  
  95.     Options.cpp = TRUE;
  96.     Options.maxdepth = MAXDEPTH;
  97.     Options.report_freq = REPORTFREQ;
  98.     Options.jitter = TRUE;
  99.     Options.samples = UNSET;
  100.     Options.gaussian = GAUSSIAN;
  101.     Options.filterwidth = UNSET;
  102.     Options.contrast.r = UNSET;
  103.     Options.ambient.r = Options.ambient.g =
  104.         Options.ambient.b = 1.0;
  105.     Options.cutoff.r = UNSET;
  106.     Options.cache = TRUE;
  107.     Options.shadowtransp = TRUE;
  108.     Options.crop[LOW][X] = Options.crop[LOW][Y] = 0.;
  109.     Options.crop[HIGH][X] = Options.crop[HIGH][Y] = 1.;
  110.     Stats.fstats = stderr;
  111.     Options.pictfile = stdout;
  112. #ifdef URT
  113.     Options.alpha = TRUE;
  114.     Options.exp_output = FALSE;
  115. #endif
  116.     Options.gamma = GAMMA;
  117.     Options.eyesep = UNSET;
  118. #ifdef LINDA
  119.     Options.workers = WORKERS;
  120. #endif
  121.  
  122.     Options.totalframes = 1;
  123.     Options.startframe = 0;
  124.     Options.starttime = 0.;
  125.     Options.framelength = 1.;
  126.     Options.shutterspeed = 0.;
  127.  
  128.     TopMedium.index = DEFAULT_INDEX;
  129.     TopMedium.statten = 1.0;
  130.     NoiseInit();            /* Initialize values for Noise() */
  131.  
  132.     /*
  133.      * Top of object definition stack points to the World object.
  134.      * The World object is always a list.
  135.      */
  136.     Defstack = GeomStackPush(GeomListCreate(), (GeomList *)NULL);
  137.     Defstack->obj->name = strsave("World");
  138.     /* Initialize surface stack */
  139.     CurSurf = SurfPush((Surface *)NULL, (SurfList *)NULL);
  140. }
  141.  
  142. /*
  143.  * cleanup()
  144.  *
  145.  * Initialize options/variables not set on command line or in input file.
  146.  * Perform sanity checks on widow dimension, maxdepth, etc.
  147.  */
  148. void
  149. RSCleanup()
  150. {
  151.     extern Light *Lights;
  152.     extern void OpenStatsFile();
  153.     extern FILE *yyin;
  154.  
  155.     yyin = (FILE *)NULL;    /* mark that we're done reading input */
  156.  
  157.     if (Options.samples == UNSET)
  158.         Options.samples = DEFSAMPLES;
  159.  
  160.     if (Options.filterwidth == UNSET) {
  161.         if (Options.gaussian)
  162.             Options.filterwidth = FILTERWIDTH;
  163.         else
  164.             /* Default box filter width of 1.0 */
  165.             Options.filterwidth = 1.0;
  166.     }
  167.  
  168.     Options.endframe = Options.startframe + Options.totalframes -1;
  169.  
  170.     OpenStatsFile();
  171.  
  172.     ViewingSetup();
  173.  
  174.     if (Options.cutoff.r == UNSET)
  175.         Options.cutoff.r = Options.cutoff.g =
  176.             Options.cutoff.b = DEFCUTOFF;
  177.  
  178.     /*
  179.      * Set contrast.
  180.      */
  181.     if (Options.contrast.r == UNSET) {
  182.         Options.contrast.r = DEFREDCONT;
  183.         Options.contrast.g = DEFGREENCONT;
  184.         Options.contrast.b = DEFBLUECONT;
  185.     }
  186.  
  187.     /*
  188.      * Image gamma is inverse of display gamma.
  189.      */
  190.     if (fabs(Options.gamma) > EPSILON)
  191.         Options.gamma = 1. / Options.gamma;
  192.     else
  193.         Options.gamma = FAR_AWAY;
  194.  
  195.     if (Options.maxdepth < 0)
  196.         Options.maxdepth = 0;
  197.  
  198.  
  199.     LightSetup();
  200. }
  201.  
  202. void
  203. RSStartFrame(frame)
  204. int frame;
  205. {
  206.     /*
  207.      * Set the frame start time
  208.      */
  209.     Options.framenum = frame;
  210.     Options.framestart = Options.starttime +
  211.             Options.framenum*Options.framelength;
  212.     SamplingSetTime(Options.framestart, Options.shutterspeed,
  213.             Options.framenum);
  214.     /*
  215.      * Set up viewing parameters.
  216.      * Can't animate camera yet; when possible, this will
  217.      * need to be much smarter.
  218.      * RSViewing();
  219.      */
  220.  
  221.     /*
  222.      * Initialize world
  223.      */
  224.     WorldSetup();
  225. }
  226.  
  227. /*
  228.  * Initialize non-time-varying goodies.
  229.  */
  230. void
  231. RSInitialize(argc, argv)
  232. int argc;
  233. char **argv;
  234. {
  235.     /*
  236.       * Initialize variables, etc.
  237.      */
  238.     RSSetup();
  239.     /*
  240.      * Parse options from command line.
  241.      */
  242.     RSOptionsSet(argc, argv);
  243.     /*
  244.      * Process input file.
  245.      */
  246.     if (Options.verbose) {
  247.         VersionPrint();
  248.         fprintf(Stats.fstats,"Reading input file...\n");
  249.         (void)fflush(Stats.fstats);
  250.     }
  251.     RSReadInputFile();
  252.     /*
  253.      * Set variables that weren't set on command line
  254.      * or in input file.
  255.      */
  256.     RSCleanup();
  257.     /*
  258.      * Set sampling options.
  259.      */
  260.     SamplingSetOptions(Options.samples, Options.gaussian,
  261.                Options.filterwidth);
  262.     /*
  263.      * Camera is currently static; initialize it here.
  264.      */
  265.     RSViewing();
  266. }
  267.